package ru.spb.osll.myfit.wikiverifier;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableStyle;
import ru.spb.osll.myfit.server.parser.PageUtils;
import ru.spb.osll.myfit.server.parser.TableElementParser;
import ru.spb.osll.myfit.util.CollectionUtils;
import ru.spb.osll.myfit.wikiverifier.result.TableVerificationResult;
import ru.spb.osll.myfit.wikiverifier.result.VerificationResultType;

public class SuggestionProviderTest {
	private TableElementParser m_parser = new TableElementParser();

	@Test
	public void testSuggestionProvider() throws Exception {
		Table oneLineTemplate = m_parser.parseTable(CollectionUtils.list(
				"|enable advanced retention on clusters|"));
		oneLineTemplate.setStyle(TableStyle.ONE_LINE_FIXTIRE);
		
		Table setUpTemplate = m_parser.parseTable(CollectionUtils.list(
				"|cluster list|", "|name|ip address|", 
				"|cluster1|1.2.3.4|"));
		setUpTemplate.setStyle(TableStyle.SETUP_FIXTURE);
		
		SuggestionProvider suggestionProvider = new SuggestionProvider(
				CollectionUtils.list(oneLineTemplate, setUpTemplate));

		Table oneLineTable = m_parser.parseTable(CollectionUtils.list(
				"|enable retention on clusters|"));
		oneLineTable.setStyle(TableStyle.ONE_LINE_FIXTIRE);
		
		TableVerificationResult res = new TableVerificationResult(
				VerificationResultType.FAILURE, oneLineTable, "");
		suggestionProvider.provideSuggestion(res);
		PageUtils.printSuggestion(res, System.out);
		assertEquals("|enable advanced retention on clusters|\n",
				PageUtils.tableToString(res.getSuggestion()).replaceAll("\r", ""));

		Table setUpTable = m_parser.parseTable(CollectionUtils.list(
				"|clust list|", "|nam|ip addr|",
				"|cluster1|1.2.3.4|"));
		setUpTable.setStyle(TableStyle.SETUP_FIXTURE);
		res = new TableVerificationResult(VerificationResultType.FAILURE,
				setUpTable, "");
		suggestionProvider.provideSuggestion(res);
		PageUtils.printSuggestion(res, System.out);
		assertEquals("|cluster list|\n|name|ip address|\n|cluster1|1.2.3.4|\n",
				PageUtils.tableToString(res.getSuggestion()).replaceAll("\r", ""));
	}
}
